package com.naiterui.ehp.bs.im.service.message.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.naiterui.ehp.bs.im.network.transfer.Transfer;
import com.naiterui.ehp.bs.im.utils.Constants;

/**
 * 离线消息处理器
 */
@Service
public class OfflineMessageHandler {

    /**
     * LOGGER
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(OfflineMessageHandler.class);

    /**
     * 向客户端发送消息的传输对象(patient)
     */
    @Autowired
    @Qualifier("patientTransfer")
    private Transfer patientTransfer;

    /**
     * 向客户端发送消息的传输对象(doctor)
     */
    @Autowired
    @Qualifier("doctorTransfer")
    private Transfer doctorTransfer;

    public void sendOfflineMessages(String userMark, Long userId) {

        // 检测toId
        if (userId == null || userId <= 0) {
            return;
        }

        if (userMark.startsWith(Constants.PREFIX_DR)) {
            /** 医生online */
            doctorTransfer.handleOfflineMessage(userId);
        } else if (userMark.startsWith(Constants.PREFIX_PT)) {
            /** 患者online */
            patientTransfer.handleOfflineMessage(userId);
        }
    }
}
